Esempio n. 1
0
    def start_of_simulation(self, ledger, emission_rate, trading_calendar,
                            sessions, benchmark_source):
        daily_returns_series = benchmark_source.daily_returns(
            sessions[0],
            sessions[-1],
        )
        self._daily_returns = daily_returns_array = daily_returns_series.values
        self._daily_cumulative_returns = np.cumprod(1 +
                                                    daily_returns_array) - 1
        self._daily_annual_volatility = (
            daily_returns_series.expanding(2).std(ddof=1) *
            np.sqrt(252)).values

        if emission_rate == "daily":
            self._minute_cumulative_returns = NamedExplodingObject(
                "self._minute_cumulative_returns",
                "does not exist in daily emission rate",
            )
            self._minute_annual_volatility = NamedExplodingObject(
                "self._minute_annual_volatility",
                "does not exist in daily emission rate",
            )
        else:
            open_ = trading_calendar.session_open(sessions[0])
            close = trading_calendar.session_close(sessions[-1])
            returns = benchmark_source.get_range(open_, close)
            self._minute_cumulative_returns = (1 + returns).cumprod() - 1
            self._minute_annual_volatility = pd.Series(
                minute_annual_volatility(
                    returns.index.normalize().view("int64"),
                    returns.values,
                    daily_returns_array,
                ),
                index=returns.index,
            )
Esempio n. 2
0
    def start_of_simulation(self,
                            ledger,
                            emission_rate,
                            trading_calendar,
                            sessions,
                            benchmark_source):
        daily_returns_series = benchmark_source.daily_returns(
            sessions[0],
            sessions[-1],
        )
        self._daily_returns = daily_returns_array = daily_returns_series.values
        self._daily_cumulative_returns = (
            np.cumprod(1 + daily_returns_array) - 1
        )
        self._daily_annual_volatility = (
            daily_returns_series.expanding(2).std(ddof=1) * np.sqrt(252)
        ).values

        if emission_rate == 'daily':
            self._minute_cumulative_returns = NamedExplodingObject(
                'self._minute_cumulative_returns',
                'does not exist in daily emission rate',
            )
            self._minute_annual_volatility = NamedExplodingObject(
                'self._minute_annual_volatility',
                'does not exist in daily emission rate',
            )
        else:
            open_ = trading_calendar.session_open(sessions[0])
            close = trading_calendar.session_close(sessions[-1])
            returns = benchmark_source.get_range(open_, close)
            self._minute_cumulative_returns = (
                (1 + returns).cumprod() - 1
            )
            self._minute_annual_volatility = pd.Series(
                minute_annual_volatility(
                    returns.index.normalize().view('int64'),
                    returns.values,
                    daily_returns_array,
                ),
                index=returns.index,
            )