2727from sklearn .discriminant_analysis import QuadraticDiscriminantAnalysis
2828
2929import warnings
30- warnings .filterwarnings ("ignore" , category = DeprecationWarning )
30+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
3131
3232
3333def get_time ():
34- return localtime (timezone .now ())
34+ return timezone .localtime (timezone .now ())
35+
3536
3637class TimeStampedModel (models .Model ):
37- created_on = models .DateTimeField (null = False , default = get_time , db_index = True )
38- modified_on = models .DateTimeField (null = False , default = get_time )
38+ created_on = models .DateTimeField (null = False , auto_now_add = True , db_index = True )
39+ modified_on = models .DateTimeField (null = False , auto_now = True )
3940
4041 def get_readonly_fields (self , request , obj = None ):
4142 return [f .name for f in self ._meta .get_fields ()]
@@ -46,10 +47,6 @@ def has_add_permission(self, request, obj=None):
4647 def has_delete_permission (self , request , obj = None ):
4748 return False
4849
49- def save (self , * args , ** kwargs ):
50- self .modified_on = get_time ()
51- return super (TimeStampedModel , self ).save (* args , ** kwargs )
52-
5350 class Meta :
5451 abstract = True
5552
@@ -58,8 +55,8 @@ def url_to_edit_object(self):
5855 return '<a href="{0}">Edit {1}</a>' .format (url , escape (str (self )))
5956
6057class AbstractedTesterClass (models .Model ):
61- created_on = models .DateTimeField (null = False , default = get_time )
62- modified_on = models .DateTimeField (null = False , default = get_time )
58+ created_on = models .DateTimeField (null = False , auto_now_add = True )
59+ modified_on = models .DateTimeField (null = False , auto_now = True )
6360
6461 def get_readonly_fields (self , request , obj = None ):
6562 return [f .name for f in self ._meta .get_fields ()]
@@ -70,17 +67,13 @@ def has_add_permission(self, request, obj=None):
7067 def has_delete_permission (self , request , obj = None ):
7168 return False
7269
73- def save (self , * args , ** kwargs ):
74- self .modified_on = get_time ()
75- return super (AbstractedTesterClass , self ).save (* args , ** kwargs )
76-
7770 class Meta :
7871 abstract = True
7972
8073 def url_to_edit_object (self ):
8174 url = reverse ('admin:{0}_{1}_change' .format (self ._meta .app_label , self ._meta .model_name ), args = [self .id ])
8275 return '<a href="{0}">Edit {1}</a>' .format (url , escape (str (self )))
83-
76+
8477 def confidence (self ):
8578 related = self .related_mocks ()
8679 related .exclude (percent_correct__isnull = True )
@@ -221,7 +214,7 @@ class PerformanceComp(TimeStampedModel):
221214 price_timerange_end = models .DateTimeField (null = True , default = None ,db_index = True )
222215 tr_timerange_start = models .DateTimeField (null = True , default = None )
223216 tr_timerange_end = models .DateTimeField (null = True , default = None )
224-
217+
225218
226219class TradeRecommendation (TimeStampedModel ):
227220 symbol = models .CharField (max_length = 30 )
@@ -313,7 +306,7 @@ def get_classifier(self,train=True,test=True):
313306 price_datasets [1 ].append (do_buy )
314307 except Exception as e :
315308 pass
316-
309+
317310 data = price_datasets
318311 if self .timedelta_back_in_granularity_increments == 0 :
319312 train_data = data
@@ -338,7 +331,7 @@ def get_classifier(self,train=True,test=True):
338331
339332 clf .fit (self .X_train , self .y_train )
340333 score = clf .score (self .X_test , self .y_test )
341-
334+
342335 # Plot the decision boundary. For that, we will assign a color to each
343336 # point in the mesh [self.x_min, m_max]x[self.y_min, self.y_max].
344337
@@ -347,7 +340,7 @@ def get_classifier(self,train=True,test=True):
347340 self .ravel_args .append (self .xz [i ].ravel ())
348341
349342 self ._input = np .column_stack (self .ravel_args )
350-
343+
351344 if hasattr (clf , "decision_function" ):
352345 self .Z = clf .decision_function (self ._input )
353346 else :
@@ -370,7 +363,7 @@ def get_classifier(self,train=True,test=True):
370363 all_output = all_output + str (('stats_debug' ,stats ))
371364 self .percent_correct = int (pct_correct * 100 )
372365 self .prediction_size = len (test_data [0 ])
373-
366+
374367 all_output = all_output + str ((self .name ,round (score * 100 )))
375368 self .score = score * 100
376369 end_time = int (time .time ())
@@ -400,7 +393,7 @@ def graph(self,filename):
400393 figure = plt .figure (figsize = (27 , 9 ))
401394 figure .max_num_figures = 5
402395 matplotlib .figure .max_num_figures = 5
403- i = 0
396+ i = 0
404397 cm = plt .cm .RdBu
405398 cm_bright = ListedColormap (['#00FF00' ,'#FF0000' , '#0000FF' ])
406399 ax = plt .subplot (1 , 1 , i )
@@ -530,9 +523,9 @@ def get_nn(self,train=True):
530523 except ImportError :
531524 FNN = buildNetwork (DS .indim , self .hiddenneurons , DS .outdim , bias = self .bias , recurrent = self .recurrent )
532525 FNN .randomize ()
533-
526+
534527 TRAINER = BackpropTrainer (FNN , dataset = DS , learningrate = self .learningrate , \
535- momentum = self .momentum , verbose = False , weightdecay = self .weightdecay )
528+ momentum = self .momentum , verbose = False , weightdecay = self .weightdecay )
536529
537530 if train :
538531 for i in range (self .epochs ):
@@ -546,12 +539,12 @@ def recommend_trade(self,nn_price,last_sample, fee_amount = get_fee_amount()):
546539 fee_amount = fee_amount * settings .FEE_MANAGEMENT_STRATEGY # see desc in settings.py
547540 anticipated_percent_increase = (nn_price - last_sample ) / last_sample
548541 if abs (anticipated_percent_increase ) < fee_amount :
549- should_trade = 'HOLD'
542+ should_trade = 'HOLD'
550543 elif anticipated_percent_increase > fee_amount :
551- should_trade = 'BUY'
544+ should_trade = 'BUY'
552545 elif anticipated_percent_increase < fee_amount :
553546 should_trade = 'SELL'
554- return should_trade
547+ return should_trade
555548
556549 def predict (self ,sample ):
557550 last_sample = sample [- 1 ]
0 commit comments