import pandas
import matplotlib.pyplot as plt
from op_futures.op_strategy_parser.op_futures_breakout_strategy import FuturesBreakOutStrategy
from op_futures.op_strategy_parser.op_futures_double_vwap_strategy import FuturesDoubleVwapStrategy
from op_futures.op_strategy_parser.op_futures_double_vwap_breakout_strategy import FuturesDoubleVwapBreakOutStrategy
class ContractParser:
def __init__(self, contract_name: str, source_contract_df: pandas.DataFrame = None):
self.contract_name: str = contract_name
self.source_contract_df: pandas.DataFrame = source_contract_df
def run_double_vwap_strategy(self):
futures_double_vwap_strategy = FuturesDoubleVwapStrategy(contract_name=self.contract_name, fast_windows=600, slow_windows=3600)
[futures_double_vwap_strategy.on_tick(tick={
'UpdateTime': row.UpdateTime,
'LastPrice': row.LastPrice,
'Volume': row.Volume,
}) for _, row in self.source_contract_df.iterrows()]
def run_double_vwap_breakout_strategy(self):
futures_double_vwap_breakout_strategy = FuturesDoubleVwapBreakOutStrategy(contract_name=self.contract_name, fast_windows=600, slow_windows=3600)
[futures_double_vwap_breakout_strategy.on_tick(tick={
'UpdateTime': row.UpdateTime,
'LastPrice': row.LastPrice,
'Volume': row.Volume,
}) for _, row in self.source_contract_df.iterrows()]
def run_breakout_strategy(self):
futures_breakout_strategy = FuturesBreakOutStrategy(contract_name=self.contract_name, windows=3600)
[futures_breakout_strategy.on_tick(tick={
'UpdateTime': row.UpdateTime,
'LastPrice': row.LastPrice,
'Volume': row.Volume,
}) for _, row in self.source_contract_df.iterrows()]
# -- draw picture.
self.__draw_time_openInterest_picture()
def __draw_time_openInterest_picture(self):
plt.plot(self.source_contract_df.UpdateTime, self.source_contract_df.OpenInterest, alpha=0.75, color='b')
plt.title(f'{self.contract_name}_UpdateTime_OpenInterest')
plt.xlabel("UpdateTime")
plt.ylabel("OpenInterest")
plt.gca().get_xaxis().set_visible(False)
plt.savefig(f'{self.contract_name}_UpdateTime_OpenInterest.png')
plt.close("all")
if __name__ == '__main__':
_contract_name = 'hc2410'
_contract_df = pandas.read_csv(f'{_contract_name}.csv')
_contract_df.columns = [
'Timestamp',
'UpdateTime',
'UpdateMillisec',
'InstrumentID',
'ExchangeInstrument',
'OpenPrice',
'HighestPrice',
'LowestPrice',
'LastPrice',
'Volume',
'Turnover',
'OpenInterest',
'UpperLimitPrice',
'LowerLimitPrice',
'PreClosePrice',
'PreOpenInterest',
'PriceTick',
'VolumeMultiple',
'ActionDay',
'AskPrice1', 'AskPrice2', 'AskPrice3', 'AskPrice4', 'AskPrice5',
'BidPrice1', 'BidPrice2', 'BidPrice3', 'BidPrice4', 'BidPrice5',
'AskSize1', 'AskSize2', 'AskSize3', 'AskSize4', 'AskSize5',
'BidSize1', 'BidSize2', 'BidSize3', 'BidSize4', 'BidSize5'
]
ContractParser(contract_name=_contract_name, source_contract_df=_contract_df).run_breakout_strategy()
# ContractParser(contract_name=_contract_name, source_contract_df=_contract_df).run_double_vwap_strategy()
# ContractParser(contract_name=_contract_name, source_contract_df=_contract_df).run_double_vwap_breakout_strategy()