# Path: OnePy/constants.py
# class ActionType(Enum):
# 
#     Buy = 'Buy'
#     Sell = 'Sell'
#     Short = 'Short'
#     Cover = 'Cover'
# 
#     Exit_all = 'Exit_all'
#     Cancel = 'Cancel'
# 
# Path: OnePy/sys_module/metabase_env.py
# class OnePyEnvBase:
#     """作为基类，提供env共享单例给各个模块"""
#     env = Environment


import abc
import pandas as pd
from collections import UserDict, UserList, deque
from typing import Deque, Dict, List, Union
from OnePy.constants import ActionType
from OnePy.sys_module.metabase_env import OnePyEnvBase
            self.data = [dict(date=self.env.fromdate, value=initial_value)]

    def change_initial_value(self, value: int):
        self.data[0]['value'] = value

    def latest(self, index: int = -1) -> float:
        return self.data[index]['value']

    def dataframe(self) -> pd.DataFrame:
        dataframe = pd.DataFrame(self.data)
        dataframe.rename(columns=dict(value=self.name), inplace=True)
        dataframe.set_index('date', inplace=True)
        dataframe.index = pd.to_datetime(dataframe.index)
        result = dataframe[~dataframe.index.duplicated(keep='last')]

        first = dataframe.ix[: 1]
        result = pd.concat([first, result])
        result.sort_index(inplace=True)

        return result

    def plot(self):
        self.dataframe().plot()


class PositionSeries(SeriesBase):
    name = 'position'

    @staticmethod
    def direction(action_type):

# Path: OnePy/constants.py
# class ActionType(Enum):
# 
#     Buy = 'Buy'
#     Sell = 'Sell'
#     Short = 'Short'
#     Cover = 'Cover'
# 
#     Exit_all = 'Exit_all'
#     Cancel = 'Cancel'
# 
# Path: OnePy/sys_module/metabase_env.py
# class OnePyEnvBase:
#     """作为基类，提供env共享单例给各个模块"""
#     env = Environment


# Path: OnePy/sys_module/models/base_series.py
import abc
import pandas as pd
from collections import UserDict, UserList, deque
from typing import Deque, Dict, List, Union
from OnePy.constants import ActionType
from OnePy.sys_module.metabase_env import OnePyEnvBase

            self.data = [dict(date=self.env.fromdate, value=initial_value)]

    def change_initial_value(self, value: int):
        self.data[0]['value'] = value

    def latest(self, index: int = -1) -> float:
        return self.data[index]['value']

    def dataframe(self) -> pd.DataFrame:
        dataframe = pd.DataFrame(self.data)
        dataframe.rename(columns=dict(value=self.name), inplace=True)
        dataframe.set_index('date', inplace=True)
        dataframe.index = pd.to_datetime(dataframe.index)
        result = dataframe[~dataframe.index.duplicated(keep='last')]

        first = dataframe.ix[: 1]
        result = pd.concat([first, result])
        result.sort_index(inplace=True)

        return result

    def plot(self):
        self.dataframe().plot()


class PositionSeries(SeriesBase):
    name = 'position'

    @staticmethod
    def direction(action_type):

        if action_type in [ActionType.Buy, ActionType.Short]: