def url(df_amazon, dj, nasdaq, sp, p_diff): url = 'https://markets.businessinsider.com/stocks/amzn-stock' index_url = [ 'https://markets.businessinsider.com/index/dow_jones', 'https://markets.businessinsider.com/index/s&p_500', 'https://markets.businessinsider.com/index/nasdaq_100' ] html = urlopen(url) soup = BeautifulSoup(html, 'lxml') #print(soup) price = extract_price(soup) name = extract_name(soup) #dp=extract_index() date_time = analysis.date_time_format(timezone('EST')) dp1, sp1, np1 = extract_index(index_url) dj_price = analysis.index_price_difference(dp1, dj) sp_price = analysis.index_price_difference(sp1, sp) nd_price = analysis.index_price_difference(np1, nasdaq) price_diff = analysis.calculate_price_diff(price, p_diff) if len(df_amazon) < 5: new_data = [ sp_price, nd_price, dj_price, name, date_time, price, price_diff, 0 ] #return new_data else: ma = analysis.moving_average(df_amazon) new_data = [ sp_price, nd_price, dj_price, name, date_time, price, price_diff, ma ] df_amazon.loc[len(df_amazon)] = new_data return df_amazon
def test_moving_average_with_ramp(): """ [quant.analysis] Test moving average with ramp """ result = analysis.moving_average(3, lin_ramp) np.testing.assert_array_equal(result, [np.nan, np.nan, 1, 2, 3, 4, 5, 6, 7, 8])
def test_moving_average_with_zeros(): """ [quant.analysis] Test moving average with zeros """ result = analysis.moving_average(3, zeros_array) np.testing.assert_array_equal(result, [np.nan, np.nan, 0, 0, 0, 0, 0, 0, 0, 0])
def test_moving_average_with_ones(): """ [quant.analysis] Test moving average with ones """ result = analysis.moving_average(3, ones_array) np.testing.assert_array_equal(result, [np.nan, np.nan, 1, 1, 1, 1, 1, 1, 1, 1])
def test_zero_length_moving_average(): """ [quant.analysis] Test zero-length moving average """ result = analysis.moving_average(0, lin_ramp) np.testing.assert_array_equal(result, nan_array)
def test_unit_length_moving_average(): """ [quant.analysis] Test unit-length moving average """ result = analysis.moving_average(1, lin_ramp) np.testing.assert_array_equal(result, lin_ramp)