Delta hedging - change in portfolio value over dt (short in call and long in shares) - delta

Equating the change in the portfolio value from 2 equations: the interest (risk-free) on the hedged portfolio, with theta dt +0.5sigma^2S^2gammadt; perhaps the functions are incorrect?
ssss<-90 #shareprice tttt<-.1 #time to expiry
new_delta<-greeks(bscall(ssss, 90, .1, .03, tttt, 0))[2] timestep<-0.001
``(greeks(bscall(ssss, 90, .1, .03, tttt, 0))[2]*ssss-callprice(ssss,90,.03,.1,tttt))0.03timestep
#calc1 - risk free return on hedged portfolio
``(-greeks(bscall(ssss, 90, .1, .03, tttt, 0))[6]timestep-0.5sigma^2ssss^2greeks(bscall(ssss, 90, .1, .03, tttt, 0))[3]*timestep)
#calc2 - using theta and gamma

Related

How to plot a 3d graph in Matlab with my data?

Right now I am doing a parameter sweep and I am trying to convert my data to a 3D graph to show the results in a very nice fashion. The problem is that I don't quite know how to plot it as I am having an issue with the result variable.
mute_rate = [0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625]
mute_step = linspace(-2.5, 2.5, 6)
results = [949.58, 293.53, 57.69, 53.65, 293.41, 1257.49;
279.19, 97.94, 32.60, 29.52, 90.52, 286.94;
32.96, 28.06, 19.56, 6.44, 13.47, 55.80;
2.01, 1.52, 5.38, 1.00, 0.89, 1.41;
0.61, 0.01, 18.59, 0.03, 0.56, 1.22;
1.85, 1.51, 18.64, 18.57, 18.54, 6.90]
So the first row in the result variable presents the results of the mute rate and mute step performed on the population from my genetic algorithm. For example:
0.5, -2.5 = 949.58,
0.5, -1.5 = 293.53,
0.5, -0.5 = 57.69
etc
It sounds like you want something akin to:
mesh(mute_step, mute_rate, results);
shading interp;
Other styles of plot would be surf or pcolor (for a 2d view).

Creating a responsive scatter plot with flutter

I am trying to create a venn diagram of two elements from a scatter plot widget on package fl_chart.
scatterPlot(screenSize) {
return ListView(children: [
SizedBox(
width: 500,
height: 500,
child: ScatterChart(
ScatterChartData(
scatterSpots:
_createSpots(determineCircleLocation(screenSize), screenSize),
minX: 0,
minY: 0,
maxX: screenSize.width,
maxY: screenSize.height,
borderData: FlBorderData(show: false),
...
I have this problem that whenever I resize my window the scatter circles are moving - so if at a full screen it appeared that they had no intersection, when I resize the screen it appears like it has an intersection.
I was trying to wrap my plot in a SizedBox thinking that would stop the resizing side effects but it didn't.
Here's a demo of the problem
Is there a way to prevent this from happening?
While writing this I thought that by changing maxX and maxY to be some constants could help, but it resulted even worst outcome.
because we set a direct size (no matter in which size is it running) this problem happens.
You can check the window size, then update the dot's radius based on the window size.
(I calculated a number, then multiplied with radiuses).
Watch the video below. and check the code here:
LayoutBuilder(
builder: (context, constraints) {
final size = constraints.biggest.shortestSide;
final radiusMultiplier = size / 800;
return Padding(
padding: const EdgeInsets.only(right: 18.0),
child: ScatterChart(
ScatterChartData(
scatterSpots: [
ScatterSpot(5, 7, radius: 60 * radiusMultiplier,),
ScatterSpot(8, 4, radius: 20 * radiusMultiplier,),
ScatterSpot(3, 8, radius: 70 * radiusMultiplier),
],
minX: 1,
maxX: 10,
minY: 1,
maxY: 10,
)
),
);
},
)

Fit of data as a cos^2?

I have collected this data of angles and intensities in lab to show Malus law so I have to fit the I as I=I0*cos^2(theta). I can't succeed with the cftool because it shows a curve totally different from my data, and I can't get a code that works. This is the data I got:
theta = [90, 110, 130, 135, 150, 170, 180, 190, 210, 225, 230, 250, 270, 290, 310,315,330, 350, 365, 370, 390]
I= [0.0030, 0.6240, 1.3060, 1.3320, 0.9610, 0.1900, 0.0160, 0.1970, 1.1250, 1.3480, 1.2900, 0.5660, 0.0030, 0.5750, 1.6170, 1.6760, 1.0850, 0.1380, 0.0940, 0.2250, 1.2340]
Thank you in advance for your help.
Well, I tried to code, but I couldn't get any near perfect match. I considered I0=1:
figure;
plot(theta, I)
hold on;
f = #(theta) cosd(theta)^2;
fplot(f, [0, 400])

Calculation of node betweenness from a weighted adjacency matrix

I have an adjacency matrix with the non zero elements indicating the weights of the link.The weights are decimals below 1 but are positive. For example, consider the below matrix as the weighted adjacency matrix a
array([[0. , 0.93, 0.84, 0.76],
[0.93, 0. , 0.93, 0.85],
[0.84, 0.93, 0. , 0.92],
[0.76, 0.85, 0.92, 0. ]])
I would like to obtain the node betweenness centrality of all the nodes in it. It is to be noted that my actual adjacency matrix is 2000 X 2000. I am new to networkx and hence any help will be highly appreciable.
You can try this
import networkx as nx
import numpy as np
A=np.matrix([[0. , 0.93, 0.84, 0.76, 0.64],
[0.93, 0. , 0.93, 0.85, 0 ],
[0.84, 0.93, 0. , 0.92, 0.32],
[0.76, 0.85, 0.92, 0. , 0.55],
[0.64, 0 , 0.32, 0.55, 0]])
G=nx.from_numpy_matrix(A)
betweeness_dict = nx.centrality.betweenness_centrality(G,weight='weight')
The betweeness_dict will contain the betweeness centrality of all the nodes
{0: 0.0, 1: 0.0, 2: 0.13888888888888887, 3: 0.0, 4: 0.13888888888888887}
You can read more about the documentation at this link.

how to sort multidimensional matrices along multiple columns

I have a tricky matrix manipulation issue that I could really use some help with.
I need to reorganize a series of 2d matrices so that they align most effectively across subjects. Each matrix has ~50 rows (which are the observations) and 13 columns (which designate the 'weight' of each observation on a series of 13 outcome measures). Based on the manner in which the data are created, there is no inherent meaning in the order of the rows, however I need to reorganize each matrix such that the rows contain meaning between subjects.
Specifically, I want to be able to reorder the matrices such that the specific pattern of weightings in a given row aligns with a similar pattern in the same row across a group of 20 subjects. To make matters worse, some subjects have missing rows, although all have between 45 and 50 rows.
As an example:
subject 1:
[ 0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7;
0.9, 0.8, 0.8, 0.7, 0.7, 0.6, 0.6, 0.5, 0.5, 0.4, 0.4, 0.3, 0.3]
subject 2:
[ 0.8, 0.7, 0.7, 0.6, 0.6, 0.5, 0.5, 0.4, 0.4, 0.3, 0.3, 0.2, 0.2;
0.0, 0.0, 0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.6, 0.7]
problem: row 1 in subject 1 aligns best with row 2 in subject 2 (and v.v.) and I would like to reorganize them as such [note: the real life problem is much more convoluted than this].
I apologize ahead of time for how idiosyncratic this issue is, but I really appreciate any help that anyone can give.
Mac