Beispiel #1
0
        def tesla(self):

            if not self.position:

                if self.high[0] < 900:
                    if volatility(self, self.sma_1, 1, 1):
                        self.log(
                            'Buy attempt :: ref -- (#1) < 900 %.2f, sma[0] :%.2f, sma[-1] :%.2f'
                            % (self.high[0], self.sma_1[0], self.sma_1[-1]))
                        self.order = self.buy(size=1, price=self.high[0])

                if self.high[0] > 900:
                    if volatility(self, self.sma_1, 1, 1):
                        self.log('Buy attempt :: ref -- (##### > 900 ')
                        self.order = self.buy(size=1, price=self.high[0])
                if self.sma_10[0] > 3:
                    self.log('Buying for sma 10')
                    self.order = self.buy(price=self.high[0])
            if self.position:

                if len(self.bought) > 5:
                    pass
                for i in self.bought:
                    if self.sma_10[0] > 3:
                        print('SMA 10 ---> ')
                        self.log(f'Buying for sma 10 {self.high[0]}')
                        self.order = self.buy(price=self.high[0])
                    if i < 500:
                        if i < 300:
                            # SELL COMMAND FOR LESS THEN 300
                            if (self.high[-1] - i) > 20:
                                self.log('SELL CREATE < 200 , %.2f' %
                                         self.dataclose[0])
                                self.order = self.sell()
                                self.bought.remove(i)
                            # BUY COMMAND FOR LESS THAN 300

                            if (self.sma_1[0] - self.sma_1[-2]) > 1:
                                self.log(
                                    'Buy attempt :: ref -- (#2) < 800 %.2f' %
                                    self.high[0])
                                self.order = self.buy(size=1,
                                                      price=self.high[0])

                        # ------------------------------------------------------------------::
                        # BUY COMMAND FOR LESS THEN 500
                        else:
                            if (i - self.high[-1]) > 80:  # greater then 300
                                self.log(
                                    'Buy attempted with possesion > 300 already  %.2f'
                                    % self.high[0])
                                self.order = self.buy(size=1,
                                                      price=(i -
                                                             self.high[-1]))
                            # SELL COMMAND FOR LESS THEN 500
                            # IF PRICE DIFFERS BY 50 THEN BUY
                            if (self.high[0] - i) > 50:
                                self.log('SELL CREATE < 500 , %.2f' %
                                         self.dataclose[0])
                                self.order = self.sell()
                                self.bought.remove(i)
                        # ------------------------------------------------------------------::
                    # IF I IS GREATER THEN 500
                    elif i > 500:
                        # IF VOLATILITY DIFFERENCE IS GREATER THEN 1.5
                        if (self.sma_10[0] - self.sma_10[-2]) > 1.5:
                            # THE STOCK IS SO VOLATILE THAT I WILL BUY SHARE EXTREMELY LOW BECAUSE ITS MOVING

                            if (i - self.high[-1]) > 200:
                                # BUY IF A THE HIGH IS 200 LOWER THEN AN ALREADY OBTAINED POSITION
                                self.log(
                                    'THE MARKET IS VERY VOLATILE --BUY--  %.2f'
                                    % self.high[0])
                                self.order = self.buy()
                        # ------------------------------------------------------------------::

                        # BUY COMMAND FOR GREATER THAN 500
                        if (i - self.high[-1]) > 100:
                            # self.log('Buy attempted with possesion  > 500 already  %.2f' % self.high[0])
                            self.order = self.buy()

                    # SELL COMMAND FOR GREATER THAN 500
                    if (self.high[0] - i) > 100:
                        # print(f'High: {self.high[0]}, i-value: {i}')
                        self.log(
                            'SELL CREATE:: REF -- (#3), High: %.2f, i : %.2f' %
                            (self.dataclose[0], i))
                        self.order = self.sell(size=1, price=(self.high[0]))
                        self.bought.remove(i)

                    if self.high[0] > 900:
                        if (self.sma_1[0] - self.sma_1[-1]) > 1:
                            self.log('Buy attempt ~ ref > 900)')
                            self.order = self.buy(size=1, price=self.high[0])
Beispiel #2
0
from black_scholes_model import *
import bopm

### 
# Parameters
symbol = 'qcom'
strikePrice =50;
daysToExp = 6;
riskFreeRate = 0.15;
###



data = HistoricalDataObj()
# Use annual volatility. 
data.initialize(symbol,365,1,1, 'yahoo'); 


spotPrice = data.vClose[-1:];

vola = volatility(data.vClose, 252);

bopmVal = bopm.bopm(spotPrice, strikePrice, daysToExp, riskFreeRate,vola)

bsmVal  = bsm(spotPrice, strikePrice, daysToExp, riskFreeRate, vola)


print vola
print bopmVal;
print bsmVal
Beispiel #3
0
# Distributed under the GPL license Version 3.0 ( See accompanying file
# License_ or copy at http://code.google.com/p/finance-py/LICENSE)
################################################################################
## include source path
import sys

sys.path.append("../src/")

from historical_data_obj import *
from volatility import *
import matplotlib.pyplot as plt

data = HistoricalDataObj()
data.initialize("bp", 365)

print volatility(data.vClose)


#  current minus the   previous
delta = data.vClose[1:] - data.vClose[:-1]
deltaP = delta / data.vClose[1:] * 100
deltaLn = log(data.vClose[1:] / data.vClose[:-1])
v = std(deltaLn)
# there are 252 trading days in any given year
v2 = v / sqrt(1.0 / 252.0)
print (v) * 100
print (v2) * 100


plt.hist(deltaLn * 100)
plt.show()
Beispiel #4
0
# http://code.google.com/p/finance-py/
# Distributed under the GPL license Version 3.0 ( See accompanying file 
# License_ or copy at http://code.google.com/p/finance-py/LICENSE)
################################################################################
## include source path
import sys
sys.path.append("../src/")

from historical_data_obj import * 
from volatility import * 
import matplotlib.pyplot as plt

data = HistoricalDataObj()
data.initialize("bp",365);

print volatility(data.vClose)


#  current minus the   previous
delta  = data.vClose[1:] - data.vClose[:-1] ;
deltaP = delta / data.vClose[1:] * 100;
deltaLn = log(data.vClose[1:] /data.vClose[:-1] );
v = std(deltaLn) ;
#there are 252 trading days in any given year
v2 = v / sqrt(1.0/252.0);
print(v)  * 100
print(v2) * 100



plt.hist(deltaLn * 100)
Beispiel #5
0
sys.path.append("../src/")

from historical_data_obj import *
from volatility import *
from black_scholes_model import *
import bopm

###
# Parameters
symbol = 'qcom'
strikePrice = 50
daysToExp = 6
riskFreeRate = 0.15
###

data = HistoricalDataObj()
# Use annual volatility.
data.initialize(symbol, 365, 1, 1, 'yahoo')

spotPrice = data.vClose[-1:]

vola = volatility(data.vClose, 252)

bopmVal = bopm.bopm(spotPrice, strikePrice, daysToExp, riskFreeRate, vola)

bsmVal = bsm(spotPrice, strikePrice, daysToExp, riskFreeRate, vola)

print vola
print bopmVal
print bsmVal