or not?

you can use

**.resample('Q").interpolate('cubic')**(or instead of cubic pick a different spline type)

oops. posted in the wrong thread!

or not?

you can use**.resample('Q").interpolate('cubic')** (or instead of cubic pick a different spline type)

or not?

you can use

- Cuchulainn
**Posts:**59940**Joined:****Location:**Amsterdam-
**Contact:**

This one is quite handy

- I have downloaded

1. Text editor Anaconda

2. Visual Studio Python

2. has nice IDE but I don't know how to install NumPy etc.

1. looks complete + all libraries but is a text editor (which is not to nice).

Ideally, I want to use both options in a Visual IDE. Any ideas?

Sorry, I missed this one. Fortunately, you're now all set up.This one is quite handy

I have downloaded

1. Text editor Anaconda

2. Visual Studio Python

2. has nice IDE but I don't know how to install NumPy etc.

1. looks complete + all libraries but is a text editor (which is not to nice).

Ideally, I want to use both options in a Visual IDE. Any ideas?

Is there an elegant way to order (asc, desc) a dictionary by values that wouldn't require any import?

Code: Select all

```
dic = {'Raul' : 0.8, 'tag' : 100.0, 'Cich' : 1.1, 'outrum' : 0.6}
sorted(dic.items(), key=operator.itemgetter(1), reverse=False)
#[('outrum', 0.6), ('Raul', 0.8), ('Cich', 1.1), ('tag', 100.0)]
```

I think like this?Is there an elegant way to order (asc, desc) a dictionary by values that wouldn't require any import?

Code: Select all`dic = {'Raul' : 0.8, 'tag' : 100.0, 'Cich' : 1.1, 'outrum' : 0.6} sorted(dic.items(), key=operator.itemgetter(1), reverse=False) #[('outrum', 0.6), ('Raul', 0.8), ('Cich', 1.1), ('tag', 100.0)]`

Code: Select all

```
sorted(dic.items(), key=lambda kv: kv[1] )
sorted(dic.items(), key=lambda kv: kv[1], reverse=True)
```

Nice! I had not thought about lambda here. Thank you very much, indeed.I think like this?Is there an elegant way to order (asc, desc) a dictionary by values that wouldn't require any import?

Code: Select all`dic = {'Raul' : 0.8, 'tag' : 100.0, 'Cich' : 1.1, 'outrum' : 0.6} sorted(dic.items(), key=operator.itemgetter(1), reverse=False) #[('outrum', 0.6), ('Raul', 0.8), ('Cich', 1.1), ('tag', 100.0)]`

Code: Select all`sorted(dic.items(), key=lambda kv: kv[1] ) sorted(dic.items(), key=lambda kv: kv[1], reverse=True)`

- Cuchulainn
**Posts:**59940**Joined:****Location:**Amsterdam-
**Contact:**

What about using XML text and using the XML DOM API. Does Python support this? Anyway, C# is like so

Code: Select all`dic = {'Raul' : 0.8, 'tag' : 100.0, 'Cich' : 1.1, 'outrum' : 0.6} sorted(dic.items(), key=operator.itemgetter(1), reverse=False) #[('outrum', 0.6), ('Raul', 0.8), ('Cich', 1.1), ('tag', 100.0)]`

https://stackoverflow.com/questions/949 ... -innertext

maybe XSLT

In my use-case -- which involves small amount of data -- data quite naturally come as a (Python) dictionary.What about using XML text and using the XML DOM API. Does Python support this? Anyway, C# is like so

Code: Select all

https://stackoverflow.com/questions/949 ... -innertext

maybe XSLT

BTW, Python can natively handle xml manipulations, such as re-ordering, e.g. this example on SO.

- Cuchulainn
**Posts:**59940**Joined:****Location:**Amsterdam-
**Contact:**

Nice. XML is language-independent. I reckon a Python-generated XML file can be read by C++/C#.

I just started building a small library in python, my first function seems to spit out correct values, any suggestion for improvements apprichiated.

Must I use the math function every time calling on for example sqrt?, if so this is irritating. (of course I could build a new sqrt function etc).

Must I use the math function every time calling on for example sqrt?, if so this is irritating. (of course I could build a new sqrt function etc).

Code: Select all

```
import math
# Barrier Exchange Option based on Haug-Haug: Knock-in/out Margrabe
def KnockInExcahngeOneAssetForAnother(CallPutFlag,S1,S2,H,T,r,b1,b2,v1,v2,rho):
v=math.sqrt(v1*v1+v2*v2-2*rho*v1*v2)
b=b1-b2
S=S1/S2
d1 = (math.log(S)+(b+v*v/2)*T)/(v*math.sqrt(T))
d2 = d1-v*math.sqrt(T)
if CallPutFlag=='c':
return S2*math.exp((b2-r)*T)*math.pow(S/H,1-2*b/(v*v))*GeneralisedBT('c',H*H/S,1,T,0,b,v)
else:
return S2*math.exp((b2-r)*T)*math.pow(S/H,1-2*b/(v*v))*GeneralisedBT('p',H*H/S,1,T,0,b,v)
# Generalized BT Function
def GeneralisedBT(CallPutFlag,S,X,T,r,b,v):
d1 = (math.log(S/X)+(b+v*v/2.)*T)/(v*math.sqrt(T))
d2 = d1-v*math.sqrt(T)
if CallPutFlag=='c':
return S*math.exp((b-r)*T)*CND(d1)-X*math.exp(-r*T)*CND(d2)
else:
return X*math.exp(-r*T)*CND(-d2)-S*math.exp((b-r)*T)*CND(-d1)
```

Last edited by Collector on February 24th, 2018, 11:48 pm, edited 2 times in total.

and nice it is compatible with Mac. So do this means much easier to link phyton functions into excel for Mac than C++? When I last time built a C++ function library I had to build the excel add-ins for my pc and was not able to use it on my Mac (at least not with my limited skills).xlwings seems pretty cool to interfacing python and excel.

- Cuchulainn
**Posts:**59940**Joined:****Location:**Amsterdam-
**Contact:**

If sqrt(T) is called in a loop it might be an idea to put it in a variable outside the loop. Maybe Python is clever enough (optimising compiler).

installed xlwings on my Mac, but looks like I was overoptimistic with respect to building Mac functions?

"3. UDFs: User Defined Functions (Windows only)"

http://docs.xlwings.org/en/stable/udfs.html

"3. UDFs: User Defined Functions (Windows only)"

http://docs.xlwings.org/en/stable/udfs.html

Last edited by Collector on February 24th, 2018, 1:02 pm, edited 1 time in total.

- Cuchulainn
**Posts:**59940**Joined:****Location:**Amsterdam-
**Contact:**

Are you pine-ing for the Mac fjords?

What not just use Excel-DNA (does it work on Mac?). Piece of cake.

C++ with Excel is a pain. I wrap it in C++/CLI. So easy.

What not just use Excel-DNA (does it work on Mac?). Piece of cake.

C++ with Excel is a pain. I wrap it in C++/CLI. So easy.

Code: Select all

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using ExcelDNA_CPPCLI; // Legacy C++ wrapper
namespace ExcelDNA
{
public static class MyFunctions
{ // This is now a proxy to Excel; the real stuff is C++
[ExcelFunction(Description = "My first")]
public static string SayHello(string name)
{
// return "Hello, there " + name;
return MyFunctionsCLI.SayHelloCLI(name);
}
[ExcelFunction(Description = "My Sum")]
public static string MySum()
{
double sum = MyFunctionsCLI.MySum();
string result = sum.ToString();
return result;
}
[ExcelFunction(Description = "BS")]
public static double CallPrice(double K, double T, double r, double v, double S)
{
return MyFunctionsCLI.CallPrice(K, T, r, v, S);
}
}
}
```

not so promising eitherWhat not just use Excel-DNA (does it work on Mac?). Piece of cake.

"I have solved this problem with ExcelDNA. As stated in the ExcelDNA forums it does not support Mac for Office, however there is a workaround. Install Wine for OSX and then run Microsoft Office 2003 or 2010 within it. I used a commercial distribution of Wine called Crossover and it works well. The downside of this approach is that you must install Wine on every target for your AddIn." https://stackoverflow.com/questions/222 ... -in-on-osx

GZIP: On