Black Sholes formula - excel

I found the Black Sholes Option calculator.
As you can see from the spreadsheet the adjusted stock price is given by =S*EXP(-q*T), how can I use a function in Excel to lookup for the value of q in my spreasheet?

A = Se^(-qT), then A/S = e^(-qT) and S/A = e^(qT).
Therefore, ln(S/A) = qT and so ln(S/A)/T = q as desired.
So your formula should be
=ln(S/A)/T
where S, A, and T are cell references to the values from which you want to compute the value of q.

Related

C++ Excel Automation : How to use SetFormula function for the cell elements whose row & column were unknown but will be given by the program later on?

I am working on the heritage codes which use C++ Excel Automation to output our analysis data in the excel spreadsheet. From the following article,
https://support.microsoft.com/en-us/topic/how-to-use-mfc-to-automate-excel-and-create-and-format-a-new-workbook-6f2450bc-ba35-a36a-df2f-c9dd53d7aef1
I knew we can use "range.SetFormula() function to calculate the formula results from some specific cells, for example:
range = sheet.GetRange(COleVariant("C2"), COleVariant("C6"));
range.SetFormula(COleVariant("=A2 & \" \" & B2"));
My question here is how can I use SetFormula function to point to some cell elements whose row & column are unknow but will be determined as the program runs. In specifically, I have a number of cell elements populated as my analysis runs. Different analysis will have different number of elements output to the excel spreadsheet. For example, if I have kw data, then the excel output will be populated in kw row 6 column and I also need to output some summary results based on these element underneath these populated elements. Something like this:
int kw = var_length; // the row changes depending on different analysis
DWORD numElements[2];
Range range;
range = sheet.GetRange(COleVariant(_T("A3")),COleVariant(_T("A3")));
numElements[0]= kw; //Number of rows in the range.
numElements[1]= 6; //Number of columns in the range.
saRet.Create(VT_R8, 2, numElements);
for(int iRow = 0;iRow < kw; iRow++)
{
for (iCol = 0; iCol < 6; iCol++)
{
index[0] = iRow;
index[1] = iCol;
saRet.PutElement(index, &somevalue);
}
}
range.SetValue2(COleVariant(saRet));
CString TStr;
TStr.Format(_T("A%d"), kw+2);
range = sheet.GetRange(COleVariant(TStr), COleVariant(TStr))
CString t1, t2;
t1.Format(_T("A%d"), kw/2);
t2.Format(_T("A%d"), kw);
range.SetFormula(COleVariant(L"=SUM(A&t1: A&t2)")); // Calculate the sum of second half of whole elements, Apparently, this didn't work, How can I fix this?
Here I want to sum the second half of whole elements but in the SetFormula function, I didn't know exactly row number for these element, eg, A25 - A50. The row number is dependent on the kw which is given as input from program. Different analysis, kw is different. I attempted to use TStr format to get the row number but it CAN NOT be used inside SetFormula function. Ideally I want to use formula for my summary data output so that if I change my populated the element values, the summary data output can change accordingly. I searched in your MSDN website but couldn't find any solution on how to resolve this.
Can someone help me with the issue?
Thanks in advance.

Background color for excel file with Pandas: problem with single column boundaries (for outliers)

I need to export an excel where the outliers of my dataset are highlighted in yellow. As you know, calculated with upper bound and lower bound.
I've managed to set up the function, I just can't get it to work in an iterated way so the bounds are for each column.
When I export the dataframe into an excel file, it colours the cells based on the outliers of only one variable. It doesn't work in iterated mode.
Here my code, where am I wrong?
Here I just calculate for each column the lower and the upper bound (except for Subject ID)
for col in dfm.columns.difference(['Sbj']):
Q1c = dfm[col].quantile(0.25)
Q3c = dfm[col].quantile(0.75)
IQRc = Q3 - Q1
lowc = Q1-1.5*IQR
uppc = Q3+1.5*IQR
I set the function to colour the single value based on the limit values (not iterated)
def color(v):
if v < lowc or v > uppc:
color = 'yellow'
return 'background-color: %s' % color
apply the function iteratively for each column
for col in dfm.columns.difference(['Sbj']):
df_colored = dfm.style.applymap(color)
It is obvious that something is wrong with the iteration.
Many thanks!!

How to calculate with the Poisson-Distribution in Matlab?

I’ve used Excel in the past but the calculations including the Poisson-Distribution took a while, that’s why I switched to SQL. Soon I’ve recognized that SQL might not be a proper solution to deal with statistical issues. Finally I’ve decided to switch to Matlab but I’m not used to it at all, my problem Is the following:
I’ve imported a .csv-table and have two columns with values, let’s say A and B (110 x 1 double)
These values both are the input values for my Poisson-calculations. Since I wanna calculate for at least the first 20 events, I’ve created a variable z=1:20.
When I now calculated let’s say
New = Poisspdf(z,A),
it says something like non-scalar arguments must match in size.
Z only has 20 records but A and l both have 110 records. So I’ve expanded Z= 1:110 and transposed it:
Znew = Z.
When I now try to execute the actual calculation:
Results = Poisspdf(Znew,A).*Poisspdf(Znew,B)
I always get only a 100x1 Vector but what I want is a matrix that is 20x20 for each record of A and B (based on my actual choice of z=1:20, I only changed to z=1:110 because Matlab told that they need to match in size).
So in this 20x20 Matrix there should always be in each cell the result of a slightly different calculation (Poisspdf(Znew,A).*Poisspdf(Znew,B)).
For example in the first cell (1,1) I want to have the result of
Poisspdf(0,value of A).*Poisspdf(0,value of B),
in cell(1,2): Poisspdf(0,value of A).*Poisspdf(1,value of B),
in cell(2,1): Poisspdf(1,value of A).*Poisspdf(0,value of B),
and so on...assuming that it’s in the Format cell(row, column)
Finally I want to sum up certain parts of each 20x20 matrix and show the result of the summed up parts in new columns.
Is there anybody able to help? Many thanks!
EDIT:
Poisson Matrix in Excel
In Excel there is Poisson-function: POISSON(x, μ, FALSE) = probability density function value f(x) at the value x for the Poisson distribution with mean μ.
In e.g. cell AD313 in the table above there is the following calculation:
=POISSON(0;first value of A;FALSE)*POISSON(0;first value of B;FALSE)
, in cell AD314
=POISSON(1;first value of A;FALSE)*POISSON(0;first value of B;FALSE)
, in cell AE313
=POISSON(0;first value of A;FALSE)*POISSON(1;first value of B;FALSE)
, and so on.
I am not sure if I completely understand your question. I wrote this code that might help you:
clear; clc
% These are the lambdas parameters for the Poisson distribution
lambdaA = 100;
lambdaB = 200;
% Generating Poisson data here
A = poissrnd(lambdaA,110,1);
B = poissrnd(lambdaB,110,1);
% Get the first 20 samples
zA = A(1:20);
zB = B(1:20);
% Perform the calculation
results = repmat(poisspdf(zA,lambdaA),1,20) .* repmat(poisspdf(zB,lambdaB)',20,1);
% Sum
sumFinal = sum(results,2);
Let me know if this is what you were trying to do.

keeping a running sum of a formula with conditions

I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!
You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.
I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture

Creation of vector of unknown size in Excel

I am attempting to translate my existing Matlab code into Numbers (basically Excel). In Matlab, I have the following code:
clear all; clc;
n = 30
x = 1:(n-1)
T = 295;
D = T./(n-x)
E = T/n
for i=1:(n-2)
C(i) = D(i+1) - D(i)
end
hold on
plot(x(1:end-1), C, 'rx')
plot(x, D, 'bx')
I believe everything has been solved by your formulas, there are parts of them that I don't understand otherwise I would try to figure the rest out myself. Attached is the result (Also you might like to know that the formulas you gave work and are recognized in Numbers). Im trying to figure out why (x) begins at 2 as I feel as though it should start at 1?
Also it is clear that the realistic results for the formulas only exist under certain conditions i.e. column E > 0. That being the case, what would be the easiest way to chart data with a filter so that only certain data is charted?
(Using Excel...)
Suppose you put your input values T & n in A1 & B1 respectively.
You could generate x, D & C In columns C,D & E with:
C1: =IF(ROW()<$A$1,ROW(),"")
D1: =IF(LEN(C1)>0,$A$2/($A$1-C1),"")
E1: =IF(LEN(D2)>0,D2-D1,"")
You could then pull all 3 columns down as far as you need to generate the full length of your vectors. If you then want to chart these, simply use these columns as inputs.

Resources