Esempio n. 1
0
 def test_05_(self) :
     msg = {}
     for stock, ret in T.extract() :
         value_1 = ret['Adj Close'].pct_change() + 1
         _risk, _returns = HELPER.findRiskAndReturn(value_1, period=HELPER.YEAR)
         value_1 = [_returns,_risk,_returns/_risk]
         value_1 = dict(zip(['returns','risk','sharpe'],value_1))
         value_2 = ret['Adj Close'].pct_change()
         _risk, _returns = HELPER.findRiskAndReturn(value_2, period=HELPER.YEAR)
         value_2 = [_returns,_risk,_returns/_risk]
         value_2 = dict(zip(['returns','risk','sharpe'],value_2))
         msg[stock] = value_2
         msg[stock + "+ 1"] = value_1
     msg = pd.DataFrame(msg)
     logging.info(msg.T)
Esempio n. 2
0
 def test_04_(self) :
     msg = {}
     for stock, ret in T.extract() :
         daily = HELPER.findDailyReturns(ret)
         _risk, _returns = HELPER.findRiskAndReturn(daily, period=HELPER.YEAR)
         value = [_returns,_risk,_returns/_risk]
         value = dict(zip(['returns','risk','sharpe'],value))
         msg[stock] = value
     msg = pd.DataFrame(msg).T
     logging.info(msg)
Esempio n. 3
0
    def find(cls, data, **kwargs):
        target = "period"
        period = kwargs.get(target, 0)
        target = "risk_free_rate"
        risk_free_rate = kwargs.get(target, 0.02)
        target = "span"
        span = kwargs.get(target, 2 * FINANCE.YEAR)

        data, risk_free_rate, period, span = cls.validate(
            data, risk_free_rate, period, span)
        data = FINANCE.findDailyReturns(data, period)
        if data is None:
            ret = dict(zip(cls.key_list, [0, 0, 0, 0]))
            return ret
        risk, returns = FINANCE.findRiskAndReturn(data, span)
        sharpe = 0
        if risk != 0:
            sharpe = (returns - risk_free_rate) / risk
        ret = dict(zip(cls.key_list, [returns, risk, sharpe, len(data)]))
        return ret
Esempio n. 4
0
 def _getSharpe(cls, data):
     risk, returns = FINANCE.findRiskAndReturn(data, period=FINANCE.YEAR)
     ret = TRANSFORM_SHARPE.sharpe(risk, returns, cls.risk_free_rate)
     return ret