Jelajahi Sumber

fixed bubble chart failing to load

laxaurus 8 tahun lalu
induk
melakukan
6999bed713
2 mengubah file dengan 52 tambahan dan 29 penghapusan
  1. 23 5
      finopt/opt_serve.py
  2. 29 24
      finopt/optcal.py

+ 23 - 5
finopt/opt_serve.py

@@ -50,7 +50,7 @@ class QServer(object):
         #rs = redis.Redis(r_host, r_port, r_db)
         rs = QServer.r_conn
         s_line = rs.info()
-	
+    
         html =''
         for k, v in cherrypy.request.app.config.iteritems():
             html = html + '<dt>%s</dt><dd>%s</dd>' % (k, v)
@@ -60,8 +60,8 @@ class QServer(object):
         stackpos_link = "<a href=./ws_position_chart_ex><img src='public/scale.png' width='42' height='42' />Positions (Stacked View)</a>"
         bubble_link = "<a href=./port_bubble_chart><img src='public/Market-Risk-Icon.png' width='42' height='42' />Risk Distributions</a>"
 
-	html = ''
-	s_line = ''
+    html = ''
+    s_line = ''
 
         return """<html><body><li>%s</li><li>%s</li><li>%s</li><li>%s</li><br><dl>%s</dl></br>%s</body></html>""" % (bubble_link, impl_link, pos_link, stackpos_link, html, s_line)
  
@@ -610,6 +610,7 @@ class QServer(object):
         
         
         s_acctitems, last_updated, account_no = self.ws_acct_data()
+
         print s_acctitems, last_updated, account_no
         html_tmpl = html_tmpl.replace('{{{barAcct}}}', s_acctitems)
         html_tmpl = html_tmpl.replace('{{{account_no}}}', account_no)
@@ -642,7 +643,10 @@ class QServer(object):
         s_portitems = self.ws_port_items() 
         
         litems = json.loads(s_portitems)
-        
+    
+        #2018 fix - get rid of 'FUT' contracts 
+        litems = filter(lambda x: 'FUT' not in x['contract'], litems)        
+
         # only interested in unrealized items, pos != 0 
         ldict = filter(lambda x: x['6002'] <> 0, litems)
         
@@ -670,7 +674,21 @@ class QServer(object):
         rs = QServer.r_conn
         key = cherrypy.request.app.config['redis']['redis.datastore.key.acct_summary']
         s_acctitems = rs.get(key)
-        dict = json.loads(s_acctitems)
+        acct_items = json.loads(s_acctitems)
+
+        # full set of acctitems 
+        #["EquityWithLoanValue", 1910295.05, "#3366CC"],["FullMaintMarginReq", 467308.14, "#DC3912"],["TotalCashValue", 1910246.58, "#3366CC"],["AvailableFunds", 1326159.87, "#3366CC"],["LookAheadMaintMarginReq", 467308.14, "#DC3912"],["BuyingPower", 8841065.82, "#3366CC"],["Cushion", 0.755374, "#DC3912"],["ExcessLiquidity", 1442986.91, "#3366CC"],["LookAheadInitMarginReq", 584135.17, "#3366CC"],["GrossPositionValue", 67834.78, "#DC3912"],["LookAheadAvailableFunds", 1326159.87, "#3366CC"],["FullAvailableFunds", 1326159.87, "#3366CC"],["MaintMarginReq", 467308.14, "#DC3912"],["FullInitMarginReq", 584135.17, "#3366CC"],["AccruedCash", 48.47, "#DC3912"],["NetLiquidation", 1910295.05, "#3366CC"],["FullExcessLiquidity", 1442986.91, "#3366CC"],["LookAheadExcessLiquidity", 1442986.91, "#3366CC"],["InitMarginReq", 584135.17, "#3366CC"],]
+
+
+        interested_keys = ['LookAheadInitMarginReq', 'NetLiquidation', 'AvailableFunds', 'AccruedCash', 'TotalCashValue' , 'last_updated', 'AccountType']
+        dict = {}
+        for k in interested_keys:
+            dict[k] = acct_items[k]
+        
+        
+    #if 'LookAheadNextChange' in dict.keys():
+    #    del(dict['LookAheadNextChange'])
+
         colnames = "[['Category', 'Value', { role: 'style' } ],"
         unwanted_cols = ['DayTradesRemaining','last_updated', 'AccountType']
         s_data = colnames + ''.join('["%s", %s, "%s"],' % (k, '%s'%(v[0]), '#3366CC' if float(v[0]) > 500000 else '#DC3912') if k not in unwanted_cols else '' for k, v in dict.iteritems()   )+ ']'

+ 29 - 24
finopt/optcal.py

@@ -266,9 +266,14 @@ if __name__ == '__main__':
     #spot 24119.0, X 25000, right: P, evaldate: 20150812, expiry: 20150828, rate: 0.0005, div: 0.0005, vol: 0.2000, premium: 334.0000
     #spot 24149.0, X 25200, right: P, evaldate: 20150812, expiry: 20150828, rate: 0.0005, div: 0.0005, vol: 0.2000, premium: 437.5000
     
-    results = cal_option(22363.0, 22000, 'C', '20151201', '20151230', 0.00012, 0.0328, 0.198)
+    results = cal_option(30695.0, 29800, 'P', '20180104', '20180227', 0.00012, 0.0328, 0.138)
     print ''.join ('%s=%0.4f, '%(k,v) for k, v in results.iteritems())
 #     results = cal_option(23067.0, 22000, 'P', '20151018', '20151029', 0.0009, 0.0328, 0.2918)
+
+    results = cal_implvol(30695.0, 29800, 'P', '20180104', '20180227', 0.00012, 0.0328, 0.138, 296)
+    print ''.join ('%s=%0.4f, '%(k,v) for k, v in results.iteritems())
+
+
 #     npv1 = results['npv']
 #     v1 = 0.2918
 # 
@@ -310,26 +315,26 @@ if __name__ == '__main__':
 #     print chk.advance(Date(17, October, 2015), 1, 2)
     #print get_HSI_expiry(2016)
     
-    holidays = get_hk_holidays(2017)
-
-    
-    
-    month_names = [January,
-                February,
-                March,
-                April,
-                May,
-                June,
-                July,
-                August,
-                September,
-                October,
-                November,
-                December,
-                ] 
-    for i in month_names:
-        dd = get_HSI_last_trading_day(holidays, i, 2017)
-        print dd
-        
-    print holidays	
-    print get_HSI_last_trading_day(['20170128'], 1, 2017)
+#     holidays = get_hk_holidays(2017)
+# 
+#     
+#     
+#     month_names = [January,
+#                 February,
+#                 March,
+#                 April,
+#                 May,
+#                 June,
+#                 July,
+#                 August,
+#                 September,
+#                 October,
+#                 November,
+#                 December,
+#                 ] 
+#     for i in month_names:
+#         dd = get_HSI_last_trading_day(holidays, i, 2017)
+#         print dd
+#         
+#     print holidays	
+#     print get_HSI_last_trading_day(['20170128'], 1, 2017)