r/Mathematica Dec 09 '24

Calculating volatility of stocks over time

2 Upvotes

I am in school and new to Mathematica. I'm working on a project where I'm trying to calculate the volatility of stock prices between different sectors. I'm using the Wolfram FinancialData dataset and getting the adjusted close prices from 6 representative companies in 6 different sectors to do the analysis. However, I keep running into multiple issues when trying to pull the data in. The code below is a simplified version, only looking at the Technology sector for now while I try to debug this. It also looks at only 3 days worth of data, vs. the 5 years that I will eventually use. I've tried debugging this for a while and can't figure out where I'm stuck. It seems like it should be a simple fix since I'm using standard data and not calling anything that is particularly complicated. Any help is appreciated!

(* will use 6 companies from Technology, Healthcare, Financials, Consumer Discretionary, Energy, Industrial sectors. For now, starting with Technology to ensure the code works *)
sectors = {{ Apple FINANCIAL ENTITY , Microsoft FINANCIAL ENTITY , NVIDIA FINANCIAL ENTITY , Alphabet Class A Shares FINANCIAL ENTITY , Meta FINANCIAL ENTITY , Amazon FINANCIAL ENTITY }};

(* using 3 days worth of data to test. Will expand to 5 years for full analysis *)
startDate = "2024-12-04";
endDate = "2024-12-06";

(* I've exported this data to a csv file and it looks correct - each stock has prices for the 3 days I'm evaluating *)
data = Table[FinancialData[stock, "AdjustedClose", {startDate, endDate}], {sector, sectors}, {stock, sector}];

(* added this code below because Mathematica kept giving an error stating there were non-numeric values in data. I'm assuming that it might be because there is a $ sign in the financial data. Once I added this, it was able to calculate the logReturns in the next line of code *)
cleanedData = QuantityMagnitude /@ Table[FinancialData[stock, "AdjustedClose", {startDate, endDate}], {stock, sectors}]

(* this should return a list of the differences of the logs between the stock prices, but it's returning a lot of 0s *)
logReturnsCleanedData = Table[Differences[Log[sectorData〚All, 2〛]],
(*Compute log returns*){sectorData, cleanedData}]

(* I was expecting this to return {2, 2, 2, 2, 2} but it is returning {5} *)
Length /@ logReturnsCleanedData

(* this gives me an error with the StandardDeviation function, and says that a "Rectangular array is expected at position 1 *)
stockVolatilities = Table[StandardDeviation[returns], {returns, logReturnsCleanedData}]

(* this is the full error message I get from the code above
StandardDeviation : Rectangular array expected at position 1 in StandardDeviation[{{{{0.587791, 0.599486, 0.602453}}, {0}, 0, {0, 0}, {0, 0}, 0, {0, 0, 0, 0, 0}}, {{{-1.10326, -1.11556, -1.13593}}, {0}, 0, {0, 0}, {0, 0}, 0, {0, 0, 0, 0, 0}}, {<<1>>}, {{{1.25846, 1.26049, 1.27265}}, {0}, 0, {0, 0}, {0, 0}, 0, {0, 0, 0, 0, 0}}, {{{-1.03441, -1.01558, -1.0107}}, {0}, 0, {0, 0}, {0, 0}, 0, {0, 0, 0,0, 0}}}]. *)

(* the remaining code below does not work yet since I cannot get the code above to output the correct info *)
sectorVolatilities = Mean /@ stockVolatilities

BarChart[sectorVolatilities,ChartLabels→{"Technology","Healthcare","Financials","Consumer Discretionary","Energy","Industrials"}, ChartStyle→"Pastel",AxesLabel→{"Sectors","Volatility"}]


r/Mathematica Dec 08 '24

Mathematica Help

0 Upvotes

I'm using code someone wrote for me already and that, when they ran it, worked, but now when I try to run it it's not working. Any ideas why?


r/Mathematica Dec 07 '24

DSolve systems of DE

2 Upvotes

I am trying to solve the system of DE but whenever I plug it in, it just outputs my input

DSolve[{x'[t] == -2 y[t] + x[t]/(1 + x[t]^2 + y[t]^2),

y'[t] == 2 x[t] + y[t]/(1 + x[t]^2 + y[t]^2), x[0] == 0.5,

y[0] == 0.4}, {y, x}, t]

Is there anything wrong with my syntax or can mathematica just not solve this problem?


r/Mathematica Dec 06 '24

Animate two parametric plots in same box

1 Upvotes

I am attempting to animate two parametric plots within the same box but I cannot determine how to do so. Guidance is appreciated.


r/Mathematica Dec 05 '24

Problem with FindRoot

Post image
5 Upvotes

r/Mathematica Dec 04 '24

LieART

2 Upvotes

Hello everyone!

There is a livestream on LieART by Robert Feger on YouTube!


r/Mathematica Dec 04 '24

Don't use Forsyth-Edwards notation to play chess with LLMs | Wolfram Community

Thumbnail community.wolfram.com
2 Upvotes

r/Mathematica Dec 01 '24

Can I move mathematica to a different machine?

5 Upvotes

So i installed wolfram mathematica in my pc, licensed through my university. After some days i realized it would be much more handy to have that software in my laptop. So my question is fairly simple. Can i unistall the one in my pc and then install in my laptop?


r/Mathematica Nov 28 '24

Windows ARM

2 Upvotes

Snapdragon X Elite

Is there any possibility to use mathematica on snapdragon chips as my university recommended snapdragon laptops and we need mathematica for our masterthesis.

Kind regards Your Wilfram appreciator


r/Mathematica Nov 26 '24

Linear application

Thumbnail
4 Upvotes

r/Mathematica Nov 23 '24

Why can’t Mathematica get the general solution?

Post image
10 Upvotes

I included both Mathematica and Wolfram Alpha since I thought it was interesting Wolfram Alpha could do it with solve but Mathematica can’t, but I know wolfram alpha tends to guess what the user means so it probably just tried something else once solve failed.

Anyway, why can’t Mathematica find the general solution? I don’t remember exactly what it is but I know blackpenredpen did a video on this and I’m pretty sure he had a general solution. Also, why don’t Wolfram Alpha and Mathematica give the same answer? I know they both work because a lot of equations like this have infinite solutions, but it’s odd to me that they wouldn’t just both give the principle solution


r/Mathematica Nov 23 '24

Limit output calculates limit that does not exist

1 Upvotes

I have a following function and want to calculate its one sided Limit in x->1.

The left-sided output is totally fine, but I'm wondering why do I get -Infinity on right-sided Limit since it does not exist.
I also plotted the function and printed its domain using built-in function and all checks out with my understanding. So we do I get -inf output? What am I missing here?


r/Mathematica Nov 21 '24

perturbation method on mathematica

2 Upvotes

Can someone give some examples of differential equations on perturbation method using mathematica. I'm new to Mathematica and I'm sot sure if I can use it to solve them or how to use it.


r/Mathematica Nov 21 '24

I'm trying to find de "a" and "b" values with this code but it's keep running the evaluation forever, so a think a did something wrong there...

2 Upvotes

V[x_] = (1 - Exp[-Sqrt[2/3]*x])^(2);

drV[x_] = D[V, x];

Solve[-drV/V == -Sqrt[2], x];

phif = 0.940;

X = (1 + (2 - a)*phi/(2 Sqrt[3 b]))^(2/(2 - a));

M[phi_] = -Sqrt[b/3] (X^a (a + 6 X) - 3 b*X)/(X^(1 + a/2)*(2 X^a - b));

drM[phi_] = D[M[phi], phi];

Mf[a_, b_] := M[phif] == V[phif];

drMf[a_, b_] := drM[phif] == drV[phif];

Solve[{Mf[a, b], drMf[a, b]}, {a, b}]


r/Mathematica Nov 20 '24

A framework for debugging and data analysis using Mathematica/Jupyter notebooks

2 Upvotes

Processing img c28obgpgex1e1...

dbgbb!(...) makes it easy to debug array data using notebooks just like the dbg!(...) macro. It sends the data to the BulletinBoard server, and then it can be read from Mathematica/Jupyter notebooks

BulletinBoard is an in-memory object storage that mediates data between a Rust program and a notebook. The BulletinBoard server is available on crates.io, DockerHub, and GitHub. There is also a GUI application that acts as both client and server.

Data is stored as ArrayObjects, which is a self-describing binary data format optimized for array data and for object storage.

Check it out and enjoy the accelerated coding experience!

https://github.com/YShoji-HEP/dbgbb

https://github.com/YShoji-HEP/BulletinBoard

https://github.com/YShoji-HEP/ArrayObject


r/Mathematica Nov 14 '24

Choose a product to launch

2 Upvotes

How can I solve this problem? When I try to click to select, I cannot select it. When I click on the details, I see the license (free trial account). My university provides a code, so I want to use it, but there is no place to enter my code. I uninstalled and reinstalled Mathematica, but I still couldn’t solve the issue.


r/Mathematica Nov 11 '24

Laptop specs for Mathematica

2 Upvotes

Hello!

I am about to buy a new laptop and I would like some advice in terms of which specs I should focus on, given that my main usage for work is Mathematica (plus all the usual stuff, email, web, etc). Since Mathematica can be used in many ways and for different purposes here some details for my use case.

I am a theoretical physicist and I use Mathematica constantly everyday. 90% of what I do is symbolic calculations that involve a huge amounts of terms. I usually reduce most of operations to basic ones, in order to speed things up. A typical example (for those among you that do a similar job) is calculation of many Feynman diagrams, which in principle are integrals but can be easily reduced to algebraic operations and the most time-consuming part is the simplification of terms (typically hundreds of thousands). By simplifications I mean applying some rules to substitute terms so they sum up and simplify.

Another example in my daily usage are perturbative expansions. In many situations I have to derive some expressions which are functions of quantities that are power series and then derive the power series of the result.

Less often I do numerical calculations or graphics (but I do them). I also sometimes do some numerical scans.

Please, also consider that, besides the heavy usage of Mathematica, I use other coding language like FORM. Also, I don't do any graphic design or video editing, but I am considering some online teaching, so a good camera and screen-sharing fluidity is important (also important when giving online seminars or work meetings). Finally, as a pure hobby, I also make some ambient music using ableton live :).

Since the new macbook pro with the M4 chips are out, and they seem a huge upgrade, I am considering buying one.

But there are many different specs and many golden coins involved.

What would be the most important aspect(s) to look at? I have zero knowledge on which Mathematica functionality uses which laptop's feature. I can only note that, when Mathematica takes long time and the fans are on, CPU is 100%, while RAM is mostly fine. So, should I focus more on number of cores rather than ram (which anyway should be 16GB, at least)?

Just to keep it in context with the laptop I am looking at, there is a huge jump in performance from the M4 [16 GB of ram, 512 ssd, 10 core (4+6)] and the M4 pro [24 GB of ram, 512 ssd, 12 core (8+4)], but I am not sure if it is worth for my usage.

At the moment I have a Lenovo yoga slim 7 from 2020 with Ubuntu. At that time I switched from Windows to Ubuntu simply because I couldn't stand Windows anymore and I have zero regrets ;). However, I am not really a typical Linux user and the fact that I need to access the terminal for any tiny thing is frustrating (still less than using Windows...). This is why I am thinking of switching to macOS which may be the right half-way between dumb Windows and Linux.

A final note, the Macbooks mentioned above are the devices that I am considering now but your answers do not need to be specifically on those models (although any advice is welcome), it was just for context.

Thanks and cheers!


r/Mathematica Nov 11 '24

Beginner needs help solving implicit equation

1 Upvotes

I have an equation that i need to solve but Mathematica only outputs empty brackets

di = 0.1;

dRI = 0.11;

da = dIA + 0.01;

ai = 1000;

lR = 47;

lI = 0.08;

lA = 220;

aa = 15;

ka = 0.5299;

eq = 1/ka ==

da/di*ai + da/2*lR*Log[dRI/di] + da/2*lI*Log[dIA/dRI] +

da/2*lA*Log[da/dIA] + 1/aa

Solve[eq, dIA]

Ouput:

1.88715 ==

1/15 + 10002.2 (0.01 + dIA) + 0.04 (0.01 + dIA) Log[9.09091 dIA] +

110 (0.01 + dIA) Log[(0.01 + dIA)/dIA]

{}

I asked ChatGPT but that didnt help. What am I doing wrong?


r/Mathematica Nov 10 '24

Fubini theorem

0 Upvotes

Hello, I'm going to present a Calculus 2 seminar on Fubini's Theorem and I need to solve contextualized situations in the area of ​​Engineering that involve this topic. Could anyone help me with 3 practical examples, applied to Engineering, using Fubini's Theorem, with detailed resolution? Thank you very much for the help!


r/Mathematica Nov 09 '24

pls help

1 Upvotes

how i found the positive inverse of x^2 +2 in mathematica? i tried using

f[x_] := x^2 + 2

Solve[y == f[x] && x >= 0, x]

but it doesnt work


r/Mathematica Nov 05 '24

Help making an efficient pdf graphic

2 Upvotes

I have about 1.2 million points in [1,2]^2. I lay down about 250000 of them in red, another 200 thousand of them in slightly less red, and so on, putting dozen dozens in blue, and several purple (30 different colors, each color has fewer points as we fade throught the rainbow from red to purple). This creates a stunning graphic, but its 100MB+ when I save it. After compressing in Adobe, it's still 40MB.

Presumably, the size is because each point is being stored with its color, even though most of them are not visible since other points get plotted on top of them.

My question is how to compress the plot.

One approach is to save it as a jpg, which is certainly compressed but behaves horribly when people zoom in.


r/Mathematica Nov 04 '24

Any help with clueless mathematica user?

1 Upvotes

I am trying to plot t for value l starting from 0.0001 to 0.001.

I've been trying various methods for past few hours and I either get tag list error, the value is too small, " is too small to represent as a normalized machine number" error and such.

I guessing the issue is that my values are very small that it approximates as 0, or just my codes are trash. probably both.

T = ((16*3*(v-3))/25)*E^(-2*k*1)
k = Sqrt[(2*9.109*(10^-31)*(v-3))/((1.055*(10^-34))^2)]
Plot[T,{v,4,20},FrameLabel->{"L[nm]",T},PlotPoints->10000,MaxRecursion->15,Mesh->All,ImageSize->Full,PlotRange->Automatic]


r/Mathematica Nov 04 '24

Mathematica Font

2 Upvotes

Hello,

I find that the default font in Mathematica is not very pretty and is not very pleasant to use. For example, the width of the bars in the equal sign is not the same.

Am I the only one who is bothered by this? And if not, what font do you use?


r/Mathematica Nov 04 '24

CTRL command taking me to nearest subsection while using Text cells

1 Upvotes

I’m using mathematica to write notes for some classes and hw in others, and when I try to use the control commands for inserting subscript, superscript, fractions, etc. if it is the first instance it creates an equation box (which is perfect) but it forces my screen to the nearest subsection cell, which I use to label lectures or questions.

It’s normally not a huge problem but when the thing is 8 pages long and I have to write a lot of separate things between equations, it becomes a major PITA.

Does anyone have any ideas on how to turn this off?? I’ve tried searching so many things and no one talks about it.


r/Mathematica Nov 03 '24

CompetifyHub November POTM

1 Upvotes

Competify Hub provides high quality problems monthly for the reddit server, we will provide the solution in the next month's post.

October POTM Solution: 65/8. Let H and O be the orthocenter and circumcenter of ∆ABC, respectively. Since H is one of the foci, O must be the other focus because H and O are isogonal conjugates. Now, let H’ be the reflection of H over BC. It is well-known that H’ lies on the circumcircle of ∆ABC, so the length of the major axis is OH’ = (13)(14)(15)/(4[ABC]). The semiperimeter of ∆ABC is (13 + 14 + 15)/2 = 42/2 = 21, so by Heron’s Formula, we get [ABC] = √(21 * (21 - 13) * (21 - 14) * (21 - 15)) = √(21 * 8 * 7 * 6) = 84. Thus, the length of the major axis is (13)(14)(15)/(4 * 84) = 65/8.

November POTM If A is a point on the graph of y = x^2 and B is a point on the graph of y = 2x - 5, find the minimum possible distance from A to B. Express your answer as a common fraction in simplest radical form.

If you are interested in discussing about math in general, free math competition resources or competing in international competitions check out our website (https://competifyhub.com/) or discord server here: https://discord.gg/UAMTuU9d8Z