量化交易之One Piece篇 - Futures ContractParser

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()

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值