-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolume_confirmation.py
More file actions
39 lines (33 loc) · 1.46 KB
/
Copy pathvolume_confirmation.py
File metadata and controls
39 lines (33 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
Volume Confirmation: Volume should ideally confirm the price movement. If the price of a stock is rising, higher volume
is generally considered positive, indicating increased buying pressure. Conversely, if the price is falling, higher volume
suggests greater selling pressure
'''
import pandas as pd
import yfinance as yf
from datetime import date
import matplotlib.pyplot as plt
import numpy as np
def getdata(stocksymbols):
ticker = yf.Ticker(stocksymbols)
end = date.today()
start = "2020-01-01"
df = ticker.history(interval="1d",start=start,end=end)
df.index = df.index.strftime('%d-%m-%y')
df.index = pd.to_datetime(df.index, format='%d-%m-%y')
df = df.loc[:,['Open','High','Low','Close','Volume']]
df = df.round(2)
return df
def volume_confirmation(df):
# Check if the price is rising or falling
df['Price_Movement'] = df['Close'].diff().fillna(0)
df['Volume_Confirmation'] = 'No_Volume_Confirmation'
for i in range(1, len(df)):
if df['Price_Movement'].iloc[i] > 0 and df['Volume'].iloc[i] > df['Volume'].iloc[i-1]:
df['Volume_Confirmation'].iloc[i] = 'Positive_Volume_Confirmation'
elif df['Price_Movement'].iloc[i] < 0 and df['Volume'].iloc[i] > df['Volume'].iloc[i-1]:
df['Volume_Confirmation'].iloc[i] = 'Negative_Volume_Confirmation'
# Remove temporary columns
df = df.drop(['Price_Movement'], axis=1)
df = df.fillna(0)
return df