I am using the function PiecewiseFlatForward to build a curve and I am using it by setting settlementDate as an "absolute" starting date, like PiecewiseFlatForward(settlementDate, swapHelpers, Actual360()), so that the curve should be unaffected by a resetting of the Settings.instance().evaluationDate. If I change Settings.instance().evaluationDate to a date in the past with respect to the original settlementDate, the reference date of the curve stays the same, but I get an error when trying to retrieve the forward rates (unlike when using the ForwardCurve function). Here the code, where after resetting the evaluation to a past date the same forwardRate function does not work (RuntimeError: 1st iteration: failed at 1st alive instrument, pillar March 16th, 2020, maturity March 16th, 2020, reference date November 27th, 2019: 2nd leg: negative time (-0.2) given):
calendar = TARGET()
todaysDate = Date(25, November, 2019)
Settings.instance().evaluationDate = todaysDate
settlementDate = Date(27, November, 2019)
calendar = TARGET()
swaps = {
(6,Months): 0.028067,
(12,Months): 0.030768,
(18,Months): 0.029352,
(24,Months): 0.028648,
(30,Months): 0.028532,
(36,Months): 0.028480,
(42,Months): 0.028420,
(48,Months): 0.028394,
(54,Months): 0.028382,
(60,Months): 0.028387}
fixedLegFrequency = Semiannual
fixedLegDayCounter = Thirty360()
fixedLegAdjustment = Unadjusted
swapHelpers = [ SwapRateHelper(QuoteHandle(SimpleQuote(swaps[(n,unit)])),
Period(n,unit), calendar,
fixedLegFrequency, fixedLegAdjustment,
fixedLegDayCounter, USDLibor(Period(6,Months)))
for n, unit in swaps.keys() ]
depoSwapCurve = PiecewiseFlatForward(settlementDate, swapHelpers, Actual360())
dates = [ spot+Period(i*6,Months) for i in range(0, len(swaps)) ]
rates = [ depoSwapCurve.forwardRate(d, USDLibor(Period(6,Months)).maturityDate(d), Actual360(), Simple).rate()
for d in dates ]
print rates
Settings.instance().evaluationDate = Date(12, September, 2019)
rates2 = [ depoSwapCurve.forwardRate(d, USDLibor(Period(6,Months)).maturityDate(d), Actual360(), Simple).rate()
for d in dates ]
print rates2
Is there a way to use the .forwardRate function without having to care about the evaluation date when the function used to build the curve is the PiecewiseFlatForward?
Are you sure there's nothing missing in the code you posted?
After correcting for the error NameError: name 'spot' is not defined (because spot is not defined in your code) with:
spot = calendar.advance(todaysDate, 2, Days)
it seems to work fine...
class Year
{
public int YearNumber;
public List<Month> Months = new List<Month>();
}
class Month
{
public int MonthNumber;
public List<Day> Days = new List<Day>();
}
class Day
{
public int DayNumber;
public string Event;
}
So I have a list of Years(list<year> years). How do I get the list (another list) which have the result that has duplicates event on the same day? I mean events can be happen on multiple dates, does not matter, what matters is, to find out if this any of date happens the same event from different year. . Lastly, (filter) only if its occurs more than 3 times. Example, 5 July 2014, 5 July 2017 and 5 July 2019 is 'Abc Festival', which occurs more than 3 times. So u get the date, the event, and the number of counts.
Using just the classes you show we can only group dates, where a "date" is a day in a month:
var query = from y in years
from m in y.Months
from d in m.Days
select new { m.MonthNumber, d.DayNumber }
into date
group date by date
into dateGroup
where dateGroup.Count() > 2
select dateGroup;
select dateGroup;
As you see, the core solution is to build new { m.MonthNumber, d.DayNumber } objects and group them.
I have DataFrame #1 with columns A, B, C startyear, endyear With Values:
year B C startyear endyear
2010 2 A 2012 2014
2011 2 A 2010 2013
2013 2 B .. ..
2012 2 C``
I want to create a new column called result
df = df.Withcolumn(...)
Resutt will take into consideration start and end years to compute mean of B for each year between start and en dates
if start date = 2012
end date = 2014
then result will be the mean of the sum of ( B2012 + B2013+B2014) = 2+2+2/3=2
Some advice ?
Thank you
You can use filter with two conditions and then use aggregate function to calculate mean.
df = df.filter((x_df.year >= x_df.start_yr) & (x_df.year <= x_df.end_yr))
df.agg({"B":"mean"})
I would want to initialize a gregorian date like this
boost::gregorian::date d = { 1, 1, 1 };
but year = 1 is not allowed.
How can I create a day before Jesus was born ?
The current implementation of Gregorian date supports dates in the range 1400-Jan-01 to 9999-Dec-31. So handling a date outside this range is no directly possible.
Currently I'm printing post archive dates like so with https://play.golang.org/p/P1-sAo5Qy8:
2009 Nov 10»Something happened in 2009
2005 Nov 10»Something happened 10 years ago
2009 Jun 10»Summer of 2009
Though I think it's nicer to print by year:
2009
2009 Nov 10»Something happened in 2009
2009 Jun 10»Summer of 2009
2005
2005 Nov 10»Something happened 10 years ago
How would I range reverse chronically over the Posts PostDate, to print the grouping that I want? Can it be done all in the template?
Implement the sort.Interface on your Posts struct, then sort it in reverse order.
type Posts struct {
Posts []Post
}
func (p Posts) Len() int {
return len(p.Posts)
}
func (p Posts) Less(i, j int) bool {
return p.Posts[i].PostDate.Before(p.Posts[j].PostDate)
}
func (p Posts) Swap(i, j int) {
p.Posts[i], p.Posts[j] = p.Posts[j], p.Posts[i]
}
and
posts := Posts{p}
sort.Sort(sort.Reverse(posts))
That will give you the posts in the sequence you want them.
Next you'll have to implement a func using a closure so you can check if the current year is the same as the one for the last post to get the grouping by year. If yes output just the post, otherwise output a header with the year followed by the post.
currentYear := "1900"
funcMap := template.FuncMap{
"newYear": func(t string) bool {
if t == currentYear {
return false
} else {
currentYear = t
return true
}
},
}
and to use it:
{{ range . }}{{ if newYear (.PostDate.Format "2006") }}<li><h1>{{ .PostDate.Format "2006" }}</h1></li>{{ end }}
See a working example on the Playground.