how to calculate the moving avg for stock in stock market - stock

I want to cal the moving avg for an etf, also i want to know how that can be cal on the paper? Value is available for 6 period and I want to predict the next value using macd cross.

Related

Different Correlation Coefficent for Different Time Ranges

I built a DataFrame where there are the following data:
Daily Price of Gas Future of N Day;
Daily Price of Petroil
Future of N Day;
Daily Price of Dau-Ahead Eletricity Market in
Italy;
The data are taken from 2010 to 2022 time range, so 12 years of historical time data.
The DataFrame head looks like this:
PETROIL GAS ELECTRICITY
0 64.138395 2.496172 68.608696
1 65.196161 2.482612 113.739130
2 64.982403 2.505938 112.086957
3 64.272606 2.500000 110.043478
4 65.993436 2.521739 95.260870
So on this DataFrame I tried to build the Correlation Matric throught the Pandas metod .corr() and faced one big issue:
If I take all 12 years as data I get:
almost Zero as correlation between Electricity and Petroil price;
low correlation (0.12) between Electricity and Gas price;
While if I try to split in three time range (2010-2014; 2014-2018; 2018-2022) I get really high correlation (in both case between 0.40 and 0.60).
So I am here asking these two questions:
Why I get this so high difference when I split the time ranges?
Considering I am doing this kind of analysis to use Petroil and Gas
prices to predict the electricity price, which of these two analysis
should I consider? The first one (with low correlation) that
considers the entire time range or the second one (with higher
correlation) that is split into different time ranges?
Thank you for your answers.

AWS QuickSight: maxOver() calculated field?

I am a stock trader who visualizes data in QuickSight. I identify the trades I want to submit to the market, sometimes for the same stock, at the same time, but in opposite directions depending on the price of the stock at that time. See below for an example of trades I might identify for 1/19/22 0800:
Date
Hour
Stock
Direction
Price
Volume
1/19/22
0800
Apple
BUY
$10
2
1/19/22
0800
Apple
SELL
$20
1
1/19/22
0800
Microsoft
BUY
$15
3
Using QuickSight, I want to visualize (in pivot tables and charts) the volume that I trade, using the maximum possible trade volume. For example, QuickSight simply sums the Volume column to 6, when really I want it to sum to 5, because the max possible trade volume for that hour is 5 (the Apple trades in the example are mutually exclusive, because the stock price cannot be both beneath $10, triggering a BUY, and above $20, triggering a SELL at the same date-time. Therefore, I want the day's traded volume to reflect the MAX possible volume I could have traded (2+3)).
I have used the maxOver() function as so: maxOver({volume}, [{stock}, {date}, {hour}], PRE_AGG), but I would like to view my trade volume rolled up to the day as so:
Date
Volume
1/19
5
Is there a way to do this using QuickSight calculated fields? Should this aggregation be done with a SQL custom field?
Add a new calculated field called
volume_direction_specifier
{Volume} * 10 + ifelse({Direction}='BUY', 1, 2)
This is a single number that will indicate the direction and volume. (this is needed in cases where the max possible volume is the same for both the BUY and SELL entries within the same hour).
Then compute the maxOver on this new field in a calculated field called max_volume_direction_specifier
maxOver({volume_direction_specifier}, [{stock}, {date}, {hour}], PRE_AGG)
Add a new field which will give the Volume for rows that have the max volume_direction_specifier per hour
volume_for_max_trade_volume_per_hour
ifelse(volume_direction_specifier = max_volume_direction_specifier, {volume}, null)
And finally, you should be able to add volume_for_max_trade_volume_per_hour to your table (grouped by day) and its SUM will give the maximum possible trade volume per day.

How can I get calculate buy and sell quantity in pandas?

When I have data of quantity and buy and sell program, I want to get the cumulative quantity by adding a number when it is 'buy' and deducting a number when it is 'sell'. How can I do this in pandas? I know there is .cumsum() function to add it, but I don't know how to deduct it.
You can flip the integer when selling:
df['quantity'].where(df['buy&sell'].eq('buy'), -df['quantity']).cumsum()

How to get percentage Difference in qliksense

I need one help.
I calculate a Difference Between Current Year Sale and Last Year
like.
num(Sum({$<[HSUBSEGM.descr]={"Clinker and Cement"},
[CALYEAR]={">=$(vCurrentYear)"}>}[_volume_SO]),'##.0')- num(Sum({$<[HSUBSEGM.descr]
={"Clinker and Cement"},[CALYEAR]={">
=$(vPreviousYear)<=$(vPreviousYear)"}>}[_volume_SO]),
'##.0')
so I m getting and answer Suppose.
This Year sale is 100 $ and Last Year sale was 50 $.
so total growth 50 $.
But I want to show growth in %.
In this case my Revenue growth is 50 % because it got double from last year..
the mathematical answer should be of this form
(sum(CurrentYearSales)-sum(PreviousYearSales))
/ sum(PreviousYearSales)
So using your example as a guide:
I removed some of the num() functions and applied it to only the final result and simplified the set analysis for vCurrentYear and vPreviousYear. That is purely my own style choices.
Give this a go
num(
(Sum({$<[HSUBSEGM.descr]={"Clinker and Cement"},[CALYEAR]={$(vCurrentYear)}>}[_volume_SO])
- Sum({$<[HSUBSEGM.descr]={"Clinker and Cement"},[CALYEAR]={$(vPreviousYear)}>}[_volume_SO]))
/
Sum({$<[HSUBSEGM.descr]={"Clinker and Cement"},[CALYEAR]={$(vPreviousYear)}>}[_volume_SO])
,'##0.00%')

Calculate average VBA from dynamic table

I ve a table on Excel with the week number and the weight (in Kg.)
Somebody can insert his weight every day during a week or just once or not at all. I can't manage that.
Then my table can literally change. from zero to 7 even more lines a week (like the yellow side of the image).
What I wanna do is to calculate the weight average per week. and then I will have one line for each week, when i got at least one weight (sometimes I won't have any line). We can have week without any weight so then I don't want this line at all. We can also easily have a weight for the week 2 but between the weeks 5 and 6 in the yellow table. That would happen if someone insert his weight after others.
How can I say this two weeks are similar, so we calculate the average for this two weight ?
I hope it's enough clear with this picture
Use formula below in Column C to calculate average(assume Week in column A and Weight in column B)
=AVERAGEIF(A:A,A2,B:B)
Average Column Copy->PasteSpecial value only,
then Remove Duplicates base on Week and the new Average Column